<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019\6\15 0015
 * Time: 8:54
 */

namespace BigVideo\IMooc\UserStorage;

use BigVideo\IMooc\Database\PDO;

/**
 * 数据对象映射模式之简单案例实现
 * Class UserManager
 * @package BigVideo\IMooc\UserStrorage
 */
class UserManager
{
    public function insertFind(User $user)
    {
        $pdoConn = new PDO();
        $pdoConn->connect("127.0.0.1",'root','root','user');
        $re = $pdoConn
            ->query("INSERT INTO `user` (`name`,`phone`,`created`) VALUES (".$user->getName().",".$user->getPhone().",".date("Y-m-d H:i:s",$user->getCraated()->getTimestamp()).")");
        $pdoConn->close();
        return $re;
    }

    public function findUser($id){
        $pdoConn = new PDO();
        $pdoConn->connect("127.0.0.1",'root','root','user');
        $re = $pdoConn
            ->query("SELECT * FROM `user` WHERE id = $id");
        $pdoConn->close();
        return $re;
    }

    public function findAllUser($field = '*'){
        $pdoConn = new PDO();
        $pdoConn->connect("127.0.0.1",'root','root','user');
        $re = $pdoConn
            ->query("SELECT {$field} FROM `user`")->fetch(MYSQLI_ASSOC);
        $pdoConn->close();
        return $re;
    }
}